package com.z.sys.service.impl;

import com.z.sys.model.RolePermission;
import com.z.sys.mapper.RolePermissionMapper;
import com.z.sys.service.IRolePermissionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zxy
 * @since 2020-10-14
 */
@Service
public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper, RolePermission> implements IRolePermissionService {

    @Override
    public void saveByIds(String permissionIds, String roleId) {

        List<String> idList = Arrays.asList(permissionIds.split(","));

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("role_id", roleId);
        this.removeByMap(params);
        List<RolePermission> rolePermissions = new ArrayList<>();
        idList.stream().forEach(p->{
            rolePermissions.add(new RolePermission(Integer.parseInt(p), Integer.parseInt(roleId)));
        });
        this.saveBatch(rolePermissions);
    }
    /***　　这是目前我了解到速度最快的一种*/@SuppressWarnings("unchecked")
    public static List<String> listrem(List<String> listA, List<String> listB){
        HashSet hs1 = new HashSet(listA);
        HashSet hs2 = new HashSet(listB);
        hs1.removeAll(hs2);
        List<String> listC = new ArrayList<String>();
        listC.addAll(hs1);
        return listC;
    }
}
